import os

import cv2
from tqdm import tqdm

from option import parse_args

if __name__ == '__main__':
    args = parse_args()
    # diffs = os.path.join(args.root_dir, 'diffs')
    crops, version = args.crops_dir, args.compression_version
    original_crops = os.path.join(args.root_dir, 'original_sequences', 'youtube', version, crops)
    fake_crops = os.path.join(args.root_dir, 'manipulated_sequences', args.fake_type, version, crops)
    # ori_videos_width = open(f'abnormal_width_statistics_{version}.dat').readlines()
    video_names = os.listdir(fake_crops)
    for video_name in tqdm(video_names):
        fake_video_path = os.path.join(fake_crops, video_name)
        video_name_split = video_name.split('_')
        real_video_path = os.path.join(original_crops, video_name_split[0])
        for img_name in os.listdir(fake_video_path):
            fake_img_path = os.path.join(fake_video_path, img_name)
            real_img_path = os.path.join(real_video_path, img_name)
            if os.path.exists(fake_img_path) and not os.path.exists(real_img_path):
                os.remove(fake_img_path)
